/* A simple standalone XML-RPC server written in C. */

#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#  include <windows.h>
#else
#  include <unistd.h>
#endif

#include <xmlrpc-c/base.h>
#include <xmlrpc-c/server.h>
#include <xmlrpc-c/server_abyss.h>


#ifdef WIN32
  #define SLEEP(seconds) SleepEx(seconds * 1000, 1);
#else
  #define SLEEP(seconds) sleep(seconds);
#endif
#include "tmclilib.h"
static xmlrpc_value *
call_method(xmlrpc_env * const env,
        xmlrpc_value * const paramArrayP,
        void * const user_data) {
	xmlrpc_value * account;
	xmlrpc_value * username;
	xmlrpc_value * password;
	xmlrpc_value * ilist;
	xmlrpc_value * olist;
	xmlrpc_value * elist;
	
	/* parse our argument array */
	xmlrpc_decompose_value(env, paramArrayP, "SSSS",
		&account, &username, &password, &ilist);
	if (env->fault_occurred) {
		return NULL;
	}
	/* return the value */
	return xmlrpc_build_value(env,"SSS", ilist,olist,elist);
}



int 
main(int           const argc, 
     const char ** const argv) {

    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;
    
    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method(
        &env, registryP, NULL, "call.method", &call_method, NULL);
    serverparm.config_file_name = NULL;
    serverparm.registryP        = registryP;
    serverparm.port_number      = atoi("4242");
    serverparm.log_file_name    = "/var/log/tmrpc_log";

    printf("Running XML-RPC server...\n");

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));

    /* xmlrpc_server_abyss() never returns */

    return 0;
}
